package com.lbagroup.giscovery;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.lbagroup.giscovery.R;

/** 
 * Activity for showing the detail of the tapped points of interest on the google map
 * 
 * This activity is used to show the details of a point of interest (POI)
 * A webview is used mainly to show the result based on a HTML form of the POI data. 
 * 
 * @author XH 
 * @version 2011.1107 
 * @since 0.2 
 */ 
public class DetailPOI extends Activity {


	WebView mwv; 
	/** Called when the activity is first created. */
	
	/** 
	 * In the OnCreate method, the webView control is used to show the content provided as a parameter 
	 * when the current activity is called from another activity. 
	 * 
	 */  
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.detailpoi);
        Bundle mBndl=getIntent().getExtras();
        String mTitle=mBndl.getString("title");
        String mContent=mBndl.getString("content");
        setTitle(mTitle);
        mwv = (WebView) findViewById(R.id.mywebview);
        mwv.setWebViewClient(new HelloWebViewClient());
        mwv.loadData(mContent, "text/html", "utf-8");
    }
    /** 
     * Method that is called when a key on the phone is pressed
     * In this method, the back-key on the phone is detected and used to determine if it is needed to 
     * quit the current screen.
     * 
     * @param keyCode The code of the pressed key 
     * @param event The object that represents the event of the key-pressed 
     * 
     */  
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_BACK) && mwv.canGoBack()) {
        mwv.goBack();
        return true;
    }
    if(keyCode == KeyEvent.KEYCODE_BACK){
    	if(!mwv.canGoBack()){
    		finish();
    	}
    }
    return super.onKeyDown(keyCode, event);
}

/** 
 * The inner class that extends the webview client class
 * 
 * This class is used to make sure the url is always loaded in the same webview control, instead of calling a
 * web browser in the android phone.  
 * 
 * @author XH
 * @version 2011.1105 
 * @since 0.1 
 */  
private class HelloWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }
}
}